import request from '@/utils/request'
import qs from "qs"

export default {
    //查询所有角色
    findAll() {
        return request({
            url: '/api-sys/role/roles',
            method: "get"
        })
    },
    //分页查询
    findByPage(pageNum, pageSize,sort) {
        const data = qs.stringify({ pageNum, pageSize,sort})
        return request({
            url: '/api-sys/role/roles',
            method: 'post',
            data
        })
    },
    //根据id查询数据
    findById(id) {
        return request({
            url: `/api-sys/role/role/${id}`,
            method: "get"
        })
    },
    //删除
    deleteById(id) {
        return request({
            url: `/api-sys/role/role/${id}`,
            method: 'delete',
        })
    },
    //修改
    updateById(form) {
        const data = qs.stringify({ "id": form.id, "name": form.name, "remark": form.remark })
        return request({
            url: "/api-sys/role/role",
            method: 'put',
            data
        })
    },
    //新增
    add(form) {
        const data = qs.stringify({ "name": form.name, "remark": form.remark })
        return request({
            url: "/api-sys/role/role",
            method: 'post',
            data
        })
    },
    //设置权限
    setPermission(roleId, permissions) {
        const data = qs.stringify({ "roleId": roleId, "permissions": permissions })
        return request({
            url: "/api-sys/role/permission",
            method: 'put',
            data
        })
    }

}